﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DotNetCore.BannerManagement.Domain;
using Microsoft.Practices.Repository;

using System.Globalization;

namespace DotNetCore.BannerManagement.DAL.Domain.dnc_ImageRepositoryArtifacts
{
    /// <summary>
    /// This factory class takes a dnc_Image object and generates
    /// the dbcommand object needed to call the underlying update
    /// stored proc.
    /// </summary>
    internal class dnc_ImageUpdateFactory : IDbToBusinessEntityNameMapper, IUpdateFactory<dnc_Image>
    {
        /// <summary>
        /// Creates the dnc_ImageUpdateFactory to build an update statement for
        /// the given dnc_Image object.
        /// </summary>
        /// <param name="dnc_Image">dnc_Image to update into the database.</param>
        public dnc_ImageUpdateFactory()
        {
        }
        
        #region IUpdateFactory<dnc_Image> Members

        public DbCommand ConstructUpdateCommand(Database db, dnc_Image dnc_Image)
        {
			DbCommand command = db.GetStoredProcCommand("dbo.Updatednc_Image");
			
			if(dnc_Image.ContentType != null)
			{
				db.AddInParameter(command, "contentType", DbType.String, dnc_Image.ContentType);
			}
			db.AddInParameter(command, "height", DbType.Decimal, dnc_Image.Height);
			db.AddInParameter(command, "iD", DbType.Int32, dnc_Image.ID);
			db.AddInParameter(command, "image", DbType.Binary, dnc_Image.Image);
			if(dnc_Image.Name != null)
			{
				db.AddInParameter(command, "name", DbType.String, dnc_Image.Name);
			}
			db.AddInParameter(command, "width", DbType.Decimal, dnc_Image.Width);
			return command;
        }
        #endregion
        
		#region IDbToBusinessEntityNameMapper Members
        /// <summary>
        /// Maps a field name in the database (usually a parameter name for a stored proc)
        /// to the corresponding business entity property name.
        /// </summary>
        /// <remarks>This method is intended for error message handling, not for reflection.</remarks>
        /// <param name="dbParameter">Name of field/parameter that the database knows about.</param>
        /// <returns>Corresponding business entity field name.</returns>
        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
				case "contentType":
					return "ContentType";
				case "height":
					return "Height";
				case "iD":
					return "ID";
				case "image":
					return "Image";
				case "name":
					return "Name";
				case "width":
					return "Width";
				default:
					throw new Exception(dbParameter);
			}
        }
        #endregion        
    }
}

